<script language="javascript">
function validate_frmreg2(){
    if (document.frmreg2.city_id.value==''){
        alert ('Bạn phải chọn thành phố!');
        return false;
    }
    if (document.frmreg2.manu_id.value==''){
        alert ('Bạn phải chọn thương hiệu xe!');
        return false;
    }
    if (document.frmreg2.model_id.value==''){
        alert ('Bạn phải chọn Model xe!');
        return false;
    }
    <?php if ($this->TYPE==1):?>
    if (document.frmreg2.style_id.value==''){
        alert ('Bạn phải chono5 dòng xe!');
        return false;
    }
    <?php endif;?>
    if (document.frmreg2.year.value==''){
        alert ('Thông tin bắt buộc nhập!');
        document.frmreg2.year.focus();
        return false;
    }
    if (document.frmreg2.kms.value==''){
        alert ('Thông tin bắt buộc nhập!');
        document.frmreg2.kms.focus();
        return false;
    }
    if (document.frmreg2.desc.value==''){
        document.frmreg2.desc.focus();
        alert ('Thông tin bắt buộc nhập!');
        return false;
    }
    if (document.frmreg2.price.value==''){
        /*if (document.frmreg2.price_from.value==''){
            document.frmreg2.price.focus();
            alert ('Thông tin bắt buộc nhập!');
            return false;
        }
        if (document.frmreg2.price_to.value==''){
            document.frmreg2.price.focus();
            alert ('Thông tin bắt buộc nhập!');
            return false;
        }*/
        document.frmreg2.price.focus();
        alert ('Thông tin bắt buộc nhập!');
        return false;
    }
    if (document.frmreg2.agree.checked==false){
        alert ('Bạn phải chấp nhận điều khoản sử dụng!');
        document.frmreg2.agree.focus();
        return false;
    }
    
    return true;
}
</script>
<?php echo $this->CP_MENU ?>
<ul class="step clearfix">
	<li><img src="<?php echo IMAGE_URL?>img_step01_o.gif" alt="" /></li>
    <li><img src="<?php echo IMAGE_URL?>img_step02_o.gif" alt="" /></li>
    <li><img src="<?php echo IMAGE_URL?>img_step03.gif" alt="" /></li>
</ul>
<form action="" method="post" enctype="multipart/form-data" name="frmreg2" id="frmreg2">
    <input type="hidden" value="<?php echo $this->ID?>" name="id"/>
    <input type="hidden" value="<?php echo $this->TYPE?>" name="type"/>
    <!--span style="color: red;text-align: center;margin-left: 210px;"><?php echo $this->ERROR?></span-->
    <h2 class="mh_title">Thông tin xe</h2>
    <ul class="detail_moto">
         <?php if ($this->EDIT==0) : // Không chuyển qua lại giữa oto và xe máy trong edit 08/09/2011  ?>
            <li class="clearfix" id="typesearch" style="float: left;">
                <input type="radio" id="motor" style="width: 20px; float:left; margin-left:10px" name="type" value="0" <?php if($this->TYPE==0) echo "checked='checked'";?> /><label for="motor">Xe máy</label>
                <input type="radio" id="otor" style="width: 20px; float:left; margin-left:10px" name="type" value="1" <?php if($this->TYPE==1) echo "checked='checked'";?>/><label for="otor">Ôtô</label>
            </li>
         <?php endif; ?>
        <li>
            <label for="city_id" style="width: 100px;">Thành phố</label>
            <select id="city_id" name="city_id" >
        		<option value="">--Chọn thành phố--</option>
                <?php foreach ($this->ARR_CITY as $row):?>
                    <?php if($row['alias']==$this->POST['city_id'] || $row['id']==$this->POST['city_id']):?>
                        <option value="<?php echo $row['alias']?>" selected="selected"><?php echo $row['name']?></option>
                    <?php else:?>
                        <option value="<?php echo $row['alias']?>"><?php echo $row['name']?></option>
                    <?php endif;?>
                <?php endforeach;?>
            </select>
        </li>
        <li>
        <!--Check new/edit-->
        <?php if ($this->EDIT==0){ ?>
            <label for="company" style="width: 100px;">Thương hiệu</label>
            <select id="company" name="manu_id">
        		<option value="">Thương hiệu</option> 
                <?php foreach ($this->ARR_FACTORY as $row):?>
                    <?php //if($row['alias'] == $this->POST['manu_id'] || ($row['id']) == $this->POST['manu_id']):?>
                    <?php if($row['alias'] == $this->POST['manu_id']):?>
                        <option value="<?php echo $row['alias']?>" selected="selected"><?php echo $row['name']?></option>
                    <?php else:?>
                        <option value="<?php echo $row['alias']?>" name = "<?php echo $row['name']?>"><?php echo $row['name']?></option>			
                    <?php endif;?>
                <?php endforeach;?>
				
			<input id = "manu_diffirent" name = "manu_diffirent" style ="margin: 5px 0 0 103px" maxlength="27" type = "text" class="watermark manufacture" watermark="Thương hiệu xe của bạn là gì?" value ="<?php echo $this->POST['manu_diffirent']?>">						
					
            </select>
        </li>
        <?php //var_dump($this->ARR_FACTORY); ?>
        <li>
            <label for="model" style="width: 100px;">Model</label>
            <select id="model" name="model_id" >
        		<option value="">--Chọn model--</option>
                    <?php foreach ($this->ARR_MODEL as $row):?>
                    <?php //if($row['alias']==$this->POST['model_id'] || $row['id']==$this->POST['model_id']):?>
                    <?php if($row['alias']==$this->POST['model_id']):?>
                        <option value="<?php echo $row['alias']?>" selected="selected"><?php echo $row['name']?></option>
                    <?php else:?>
                        <option value="<?php echo $row['alias']?>"><?php echo $row['name']?></option>		
                    <?php endif;?>

                <?php endforeach;?>
				<input id="model_diffirent" name="model_diffirent" style="margin: 5px 0 0 103px" maxlength="27" type = "text" class="watermark model" watermark="Model xe của bạn là gì? " value ="<?php echo $this->POST['model_diffirent']?>">						
						
            </select>
        </li>
        <li>
            <label for="style" id="txtStyle"  style="width: 100px;<?php if ($this->TYPE==1) echo "display:block;"; else echo "display:none;"?>">Dòng xe</label>
            <select id="style" name="style_id" style="<?php if ($this->TYPE==1) echo "display:block;"; else echo "display:none;"?>">
                <option value="">--Chọn dòng xe--</option>
                <?php foreach ($this->ARR_STYLE as $row):?>
                    <?php if($row['alias']==$this->POST['style_id'] || $row['id']==$this->POST['style_id']):?>
                        <option value="<?php echo $row['alias']?>" selected="selected"><?php echo $row['name']?></option>
                    <?php else:?>
                        <option value="<?php echo $row['alias']?>"><?php echo $row['name']?></option>
                    <?php endif;?>
                <?php endforeach;?>
            </select>
        </li>
        <?php } else { ?>
        <li>
            <?php //var_dump($this->ARR_FACTORY); ?>
            <label for="company" style="width: 100px;">Thương hiệu</label>
                <?php foreach ($this->ARR_FACTORY as $row):?>
                    <?php if($row['alias']==$this->POST['manu_id'] || $row['id']==$this->POST['manu_id']):?>
                        <?php if($this->POST['manu_id'] <= 0 && trim($this->POST['manu_diffirent']) != 'Thương hiệu xe của bạn là gì?'): ?>
                            <input style="color: #cccccc;" type="text" name="manu_diffirent" readonly="readonly" value="<?php echo $this->POST['manu_diffirent']?>"/>
                        <?php else: ?>
                            <input style="color: #cccccc;" type="text" name="manu_name" readonly="readonly" value="<?php echo $row['name']?>"/>
                        <?php endif;?>
                        <input type="hidden" name="manu_id" value="<?php echo $row['alias']?>"/>
                    <?php endif;?>
                <?php endforeach;?>
        </li>
         <li>
            <label for="model" style="width: 100px;">Model</label>
                  <?php foreach ($this->ARR_MODEL as $row):?>
                    <?php if($row['alias']==$this->POST['model_id'] || $row['id']==$this->POST['model_id']):?>
                        
                        <?php if($this->POST['model_id'] <= 0 && trim($this->POST['model_diffirent']) != 'Model xe của bạn là gì?'): ?>
                            <input type="text" style="color: #cccccc;" name="model_diffirent" readonly="readonly" value="<?php echo $this->POST['model_diffirent']?>"/>
                        <?php else: ?>
                            <input type="text" style="color: #cccccc;" name="model_name" readonly="readonly" value="<?php echo $row['name']?>"/>
                        <?php endif;?>
                        <input type="hidden" name="model_id" value="<?php echo $row['alias']?>"/>
                    <?php break;endif;?>
                <?php endforeach;?>
        </li>
         <?php if ($this->TYPE==1): ?>
         <li>
            <label for="style" id="txtStyle"  style="width: 100px;">Dòng xe</label>
                  <?php foreach ($this->ARR_STYLE as $row):?>
                    <?php if($row['alias']==$this->POST['style_id'] || $row['id']==$this->POST['style_id']):?>
                        <input type="text" style="color: #cccccc;" name="style_name" readonly="readonly" value="<?php echo $row['name']?>"/>
                        <input type="hidden" name="style_id" value="<?php echo $row['alias']?>"/>
                    <?php break;endif;?>
                <?php endforeach;?>
        </li>
        <?php endif; ?>
        <?php } ?>
        <!---->
        <!--edt<?/*
        
            
        */?>-->
        <li>
            <label for="year" style="width: 100px;">Đời xe:</label>
            <input type="text" size="20" maxlength="22" id="year" name="year" value="<?php echo $this->POST['year']?>"/></li>
        <li>
            <label for="kms" style="width: 100px;">Số Km:</label>
            <input type="text" size="20" id="kms" name="kms" value="<?php echo $this->POST['kms']?>"/> km</li>                    
    </ul>
    <h2 class="mh_title">Thông tin thêm</h2>
    <ul class="other_list clearfix">
    	<li>
            <label for="description" style="width: 100px;float: left;">Mô tả xe:</label>
            <textarea cols="5" rows="10" id="description" name="desc"><?php echo $this->POST['desc']?></textarea></li>
       	<!--li><textarea cols="5" rows="10" id="accessories" name="accessories" watermark="Phụ kiện xe" class="watermark"><?php echo $this->POST['accessories']?></textarea></li--> 
	</ul>
	<h2 class="mh_title">Hình ảnh</h2>
    <span style="font-size: 10px;font-style: italic; color: #4D4444;">Dung lượng hình phải nhỏ hơn 1MB, chấp nhận định *.jpg, *.gif, *.png</span>
    <ul class="detail_moto">
        <li><input type="file" name="image" size="58" class="pic"/>
        </li>
        <li><input type="file" name="image1" size="58" class="pic"/>
        
        <li><input type="file" name="image2" size="58" class="pic"/>
        
        <li>
            <label for="price" style="width: 100px;">Giá xe:</label>
            <input type="text" id="inputprice" name="price" class="price" value="<?php if ($this->POST['price'])echo $this->POST['price']?>" style="width: 210px;"/>
            VNĐ
        </li>    
        <!--li>
            <label for="price_from">Giá từ xe:</label>
            <input type="text" id="price_from" name="price_from" class=" price"  value="<?php if ($this->POST['price_from'])echo $this->POST['price_from']?>" style="width: 100px;" />
            <label for="price_to">Đến:</label>
            <input type="text" id="price_to" name="price_to" class=" price" value="<?php if ($this->POST['price_to'])echo $this->POST['price_to']?>" style="width: 100px;" />
        </li-->
        <li>
            <img id="captcha" src="/capcha.php" alt="CAPTCHA Image" />
            <input type="text" name="captcha_code" maxlength="4" style="width: 100px;margin-left: 33px;"/>
            
        </li>
        <li>
            <a style="" href="javascript:void(0);" onclick="document.getElementById('captcha').src = '/capcha.php?' + Math.random(); return false">
            [ Mã bảo mật khác ]</a>
        </li>
        <li class="clearfix">            
            <input type="checkbox" id="check01" name="agree" value="1" class="regist"  />
            <label for="check01">Tôi đã đọc và chấp nhận các <a href = "/content/huongdandk"><font color = "blue">Điều khoản sử dụng</font></a></label></li>              
    </ul>
    <p class="comfirm"><a href="javascript:void(0);" class="click_btn" onclick="form_submit();"><span>Xác nhận</span></a></p>
</form>
<script type="text/javascript" language="javascript">
function form_submit(){
        if(validate_frmreg2()){
            $.blockUI({ 
                message: 'Đang xử lý...', 
                css: { border: '1px solid #a00' } 
            });
            document.frmreg2.submit();   
        }
    }
$(function(){
    $('#frmreg2 #company').change(function(){
        var manu_id=$(this).val();
        $.ajax({
            url:'/ajax/get-model',
            type:'post',
            data:{type:type,manu_id:manu_id},
            beforeSend:showLoading,
            success:function(data){
                $('#frmreg2 #model').html(data);
            } ,
            complete:hideLoading         
        });   
        
    });   
    
	$(document).ready(function(){
		$('#manu_diffirent').hide();
		var company_name = $('#company').val();
		if (company_name == 'xm-khac' ||company_name == 'oto-khac')
			$('#manu_diffirent').show();
		$('#model_diffirent').hide();
		var model_name = $('#model').val();
		if (model_name == 'model-xm-khac')
			$('#model_diffirent').show();
	});
	
	$('#company').change(function(){
		if($(this).val() == 'xm-khac'||$(this).val() == 'oto-khac')
			$('#manu_diffirent').show();
		else $('#manu_diffirent').hide();
	});
	

	
	$('.detail_moto #model').change(function(){
		if($(this).val() == 'model-xm-khac')
			$('#model_diffirent').show();
		else $('#model_diffirent').hide();
	});
	
    $('#frmreg2 input[name=type]').each(function(){
        $(this).change(function(){
            var checked= $(this).val();
                if(checked==1){
                        $('#frmreg2 #style').show();
                        $('#txtStyle').show()
                        $('#frmreg2 #style').attr('disabled',false)
                    }else{
                        $('#frmreg2 #style').hide();
                        $('#txtStyle').hide()
                        $('#frmreg2 #style').attr('disabled',true)
                    }
            $.post('/ajax/get-manufacture',{type:checked},function(resp){
    			if(isNaN(resp)){
    				$('#frmreg2 #company').html(resp);
                    hideLoading();
    			}
            });
        });
    });

    
    <?php if($this->CALL_SCRIPT):?>
         <?php echo $this->CALL_SCRIPT?>;
    <?php endif;?> 
    
   
   $("#inputprice").priceFormat({prefix: "",centsSeparator: "",thousandsSeparator: ".", centsLimit:0, limit:12});   
   $("#kms").priceFormat({prefix: "",centsSeparator: "",thousandsSeparator: ".", centsLimit:0, limit:10});

});
    
</script>
<?php echo $this->Google_Conversion?>